package com.inspur.edp.bef.bizentity.operation;

import com.ctc.wstx.util.StringUtil;
import com.inspur.edp.cef.designtime.api.entity.CustomizationInfo;
import com.inspur.edp.cef.designtime.api.util.Guid;
import com.inspur.edp.bef.bizentity.beenum.BEOperationType;
import com.inspur.edp.bef.bizentity.GspBizEntityObject;
import org.springframework.util.ObjectUtils;

/**
 * BE��������. BE�������ǻ��ڷ����ҵ���߼������ģ�ÿ�������������е�һ��������
 * ��BE���û������˸ò��ϵ�������û��о�������̨�����Ĵ��ڡ�
 * Ӧ��ȷ��BE������Code��Name��Method��Code��Name��һ�¡�
 * 
 */
public abstract class BizOperation implements Cloneable {

	// region ���캯��

	// endregion

	// region ����

	/**
	 * ��������
	 * 
	 */
	private String privateID;

	public final String getID() {
		return privateID;
	}

	public final void setID(String value) {
		privateID = value;
	}

	/**
	 * ҵ������
	 * 
	 */
	private String privateCode;

	public final String getCode() {
		return privateCode;
	}

	public final void setCode(String value) {
		privateCode = value;
	}

	/**
	 * ��ʾ����
	 * 
	 */
	private String privateName;

	public final String getName() {
		return privateName;
	}

	public final void setName(String value) {
		privateName = value;
	}

	/**
	 * ����
	 * 
	 */
	private String privateDescription;

	public final String getDescription() {
		return privateDescription;
	}

	public final void setDescription(String value) {
		privateDescription = value;
	}

	// /// <summary>
	///// ����Id
	///// </summary>
	// public virtual string MethodId { get; set; }

	/**
	 * ��Ӧ����ʵ��Id
	 * 
	 */
	private String privateComponentId;

	public String getComponentId() {
		return privateComponentId;
	}

	public void setComponentId(String value) {
		privateComponentId = value;
	}

	/**
	 * ��Ӧ����ʵ��Name
	 * 
	 */
	private String privateComponentName;

	public String getComponentName() {
		return privateComponentName;
	}

	public void setComponentName(String value) {
		privateComponentName = value;
	}

	/**
	 * ��Ӧ����ʵ�����
	 * 
	 */
	private String privateComponentPkgName;

	public String getComponentPkgName() {
		return privateComponentPkgName;
	}

	public void setComponentPkgName(String value) {
		privateComponentPkgName = value;
	}

	/**
	 * �Ƿ�ɼ�
	 * 
	 */
	private boolean privateIsVisible;

	public final boolean getIsVisible() {
		return privateIsVisible;
	}

	public final void setIsVisible(boolean value) {
		privateIsVisible = value;
	}

	/**
	 * ��������
	 * 
	 */
	public abstract BEOperationType getOpType();

	/**
	 * ������Node�ڵ�
	 * 
	 */
	private GspBizEntityObject privateOwner;

	public final GspBizEntityObject getOwner() {
		return privateOwner;
	}

	public final void setOwner(GspBizEntityObject value) {
		privateOwner = value;
	}

	/**
	 * ������չģ��Ԫ����ID
	 * 
	 */
	private String privateBelongModelID;

	public final String getBelongModelID() {
		return privateBelongModelID;
	}

	public final void setBelongModelID(String value) {
		privateBelongModelID = value;
	}

	private boolean privateIsRef;

	public final boolean getIsRef() {
		return privateIsRef;
	}

	public final void setIsRef(boolean value) {
		privateIsRef = value;
	}

	private boolean privateIsGenerateComponent;

	public final boolean getIsGenerateComponent() {
		return privateIsGenerateComponent;
	}

	public final void setIsGenerateComponent(boolean value) {
		privateIsGenerateComponent = value;
	}

	private CustomizationInfo customizationInfo = new CustomizationInfo();
	public CustomizationInfo getCustomizationInfo() {
		return this.customizationInfo;
	}

	public void setCustomizationInfo(CustomizationInfo customizationInfo) {
		this.customizationInfo = customizationInfo;
	}

	// endregion

	// region ����

	/**
	 * Equals����
	 * 
	 * @param obj
	 * @return
	 */
	@Override
	public boolean equals(Object obj) {
		if (obj == null) {
			return false;
		}
		if (obj == this) {
			return true;
		}
		if (obj.getClass() != getClass()) {
			return false;
		}
		return equals((BizOperation) obj);
	}

	/**
	 * Equals����
	 * 
	 * @param other
	 * @return
	 */
	protected boolean equals(BizOperation other) {
		// && Equals(MethodId, other.MethodId)
		// && IsEnabled == other.IsEnabled
		// && IsExcuteAfterVD.equals(other.IsExcuteAfterVD)
		// && IsOnlyExcuteAfterVD.equals(other.IsOnlyExcuteAfterVD)
		// && IsFinal.equals(other.IsFinal)

		//getComponentId().equals(other.getComponentId())
		return getID().equals(other.getID()) && getCode().equals(other.getCode()) && getName().equals(other.getName())
				&& ObjectUtils.nullSafeEquals(getComponentId(), other.getComponentId())&& (new Boolean(getIsVisible())).equals(other.getIsVisible())
				&& getOpType() == other.getOpType() && (new Boolean(getIsRef())).equals(other.getIsRef());
	}

	/**
	 * ��дGetHashCode
	 * 
	 * @return
	 */
	@Override
	public int hashCode() {
		{
			int hashCode = (getID() != null ? getID().hashCode() : 0);
			hashCode = (hashCode * 397) ^ (getCode() != null ? getCode().hashCode() : 0);
			hashCode = (hashCode * 397) ^ (getName() != null ? getName().hashCode() : 0);
			// hashCode = (hashCode * 397) ^ (ElementName != null ?
			// ElementName.getHashCode() : 0);
			// hashCode = (hashCode * 397) ^ (MethodId != null ? MethodId.getHashCode() :
			// 0);
			hashCode = (hashCode * 397) ^ (getComponentId() != null ? getComponentId().hashCode() : 0);
			hashCode = (hashCode * 397) ^ (new Boolean(getIsVisible())).hashCode();
			hashCode = (hashCode * 397) ^ (int) getOpType().getValue();
			hashCode = (hashCode * 397) ^ (new Boolean(getIsRef())).hashCode();
			// hashCode = (hashCode * 397) ^ (IsEnabled.getHashCode() * 397);
			// hashCode = (hashCode * 397) ^ (IsExcuteAfterVD.getHashCode() * 397);
			// hashCode = (hashCode * 397) ^ (IsOnlyExcuteAfterVD.getHashCode() * 397);
			// ^ IsFinal.getHashCode();
			return hashCode;
		}
	}

	/**
	 * ��¡BE����
	 * 
	 * @param isGenerateId �Ƿ�����Id
	 * @return ����һ���µĶ�������
	 */
	public BizOperation clone(boolean isGenerateId) {
		Object tempVar = null;
		try {
			tempVar = super.clone();
		} catch (CloneNotSupportedException e) {
			return null;
		}
		BizOperation result = (BizOperation) ((tempVar instanceof BizOperation) ? tempVar : null);

		if (isGenerateId) {
			result.setID(Guid.newGuid().toString());
			result.setCode("Copyof" + result.getCode());
		}

		return result;
	}

	/**
	 * ��¡BE����
	 * 
	 * @return ���ص�ǰ�����ĸ���
	 */
	public BizOperation clone() {
		return clone(false);
	}

	/**
	 * ��дToString 
	 * 
	 * @return ���ض�������
	 */
	@Override
	public String toString() {
		return String.format("Id:%1$s,Code:%2$s,Name:%3$s,ComponentId:%4$s", getID(), getCode(), getName(),
				getComponentId());
	}

	protected final void mergeOperationBaseInfo(BizOperation dependentOperation) {
		setCode(dependentOperation.getCode());
		setName(dependentOperation.getName());
		setDescription(dependentOperation.getDescription());
		// MethodId = dependentOperation.MethodId;
		// TODO:method��merge
		setComponentId(dependentOperation.getComponentId());
		setBelongModelID(dependentOperation.getBelongModelID());
		setIsVisible(dependentOperation.getIsVisible());
	}

	// endregion
}